//To caculate the former adjacent number
//if it is bigger than the current one 
//then output the number else output zero
//eg input array[2,3,5,1,6,4]
//  output array[0,0,0,5,0,6]
//hint using the auxiliary stack 

#include<iostream>
#include<stack>
using namespace std;


int main()
{
	int a[]={3,2,5,1,4,6,8};
	stack<int> s;
	int* output = new int[sizeof(a)];
	
	for(int i=0; i < sizeof(a),++i)
	{
		while(!s.empty()&&s.top()<a[i])
			s.pop();
		if(s.empty())
			output[i]=0;
		else
			output[i]=s.top();
		s.push(a[i]);
	}	
	return 0;
}
